package com.shop.technicalservice.dao.deliver.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.deliver.DeliverDao;
import com.shop.technicalservice.model.deliver.Deliver;

/**
 * A data access object (DAO) providing persistence and search support for
 * Deliver entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see org.rjb.pojo.DeliverDto
 * @author MyEclipse Persistence Tools
 */

public class DeliverDaoImpl extends HibernateDaoSupport implements DeliverDao{
	private static final Log log = LogFactory.getLog(DeliverDaoImpl.class);
	// property constants
	public static final String DESCRIPTION = "description";
	public static final String AMOUNT = "amount";

	protected void initDao() {
		// do nothing
	}

	public Deliver save(Deliver transientInstance)  throws Exception{
		log.debug("saving Deliver instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		return transientInstance;
	}

	public void delete(Deliver persistentInstance)  throws Exception{
		log.debug("deleting Deliver instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
	}

	public Deliver findById(java.lang.Integer id)  throws Exception{
		log.debug("getting Deliver instance with id: " + id);
			Deliver instance = (Deliver) getHibernateTemplate().get(
					"org.rjb.Deliver", id);
			return instance;
	}

	public List findByExample(Deliver instance)  throws Exception{
		log.debug("finding Deliver instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value) throws Exception {
		log.debug("finding Deliver instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Deliver as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByDescription(Object description) throws Exception {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByAmount(Object amount)  throws Exception{
		return findByProperty(AMOUNT, amount);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Deliver instances");
			String queryString = "from Deliver";
			return getHibernateTemplate().find(queryString);
	}

	public Deliver merge(Deliver detachedInstance) {
		log.debug("merging Deliver instance");
			Deliver result = (Deliver) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Deliver instance) throws Exception {
		log.debug("attaching dirty Deliver instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Deliver instance)  throws Exception{
		log.debug("attaching clean Deliver instance");
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
	}

	 
}